import { UserCouponStatus } from "@/pages/normal/normalList/detail"
import request from "@/utils/request"

/** 优惠券类型 */
export enum CouponInfoType {
  折扣券 = 1,
  抵用券 = 2,
}

/** 优惠券使用类型 */
export enum CouponCutType {
  总费用 = 1,
  服务费 = 2,
  电费 = 3,
}

/** 优惠券状态 */
export enum CouponStatus {
  上架中 = 1,
  待上架 = 2,
}

export interface QueryCouponListParams extends PaginationParams {
  title?: string
  infoType?: CouponInfoType
  status?: CouponStatus
}

export interface Coupon {
  id: number
  title: string
  infoType: CouponInfoType
  cutType: CouponCutType
  status: CouponStatus
  /** 折扣或者减免金额 */
  cutNum: number
  /** 有效天数 */
  expireDay: number
  /** 满足金额 */
  fullMoney: number
  /** 领取数量 */
  sendNum: number
  /** 发放数量 */
  num: number
  /** 领取截止日期 */
  endTime: number
  /** 可用场站，逗号分割 */
  stationIds: string
  /** 使用范围 1全部自营场站 2 部分场站 */
  stationType: 1 | 2
  stations: {station_name: string}[]
  createTime: number
}

export async function queryCouponList(params: QueryCouponListParams) {
  return request<Coupon[]>('/app/manager/couponModuleList', {
    data: params,
  })
}

export async function getCouponDetail(params: {id: number}) {
  return request<Coupon>('/app/manager/couponModule/detail', {
    data: params,
  })
}

export async function addCouponTemplate(params: Partial<Coupon>) {
  return request('/app/manager/addCouponModule', {
    data: params,
  })
}

export async function delCoupon(params: {
  id: number, 
  status: 1 | 2 | 3, // 1:上架中, 2:待上架, 3:删除
}) {
  return request('/app/manager/statusCouponModule', {
    data: params,
  })
}

export interface QueryUserCouponListParams extends PaginationParams {
  infoId?: number
  userId?: string
  status?: UserCouponStatus
}
export interface UserCoupon {
  createTime: number
  endTime: string
  nickname: string
  telephone: string
  cutType: CouponCutType
  infoType: CouponInfoType
  title: string
  getM: number
  /** 1:全部自营场站; 2:部分场站 */
  station: 1 | 2
  /** 满足金额 */
  totalM: number
}
export async function queryUserCouponList(params: QueryUserCouponListParams) {
  return request<UserCoupon[]>('/app/manager/userCouponList', {
    data: params,
  })
}
